//
// winter - Direct2D GUI framework.
// Copyright (C) 2009 Aleksandar Dezelin 
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#ifndef FORM_H
#define FORM_H

#pragma once
#include "intrusive_ptr.h"
#include "form_host.h"

namespace winter {

///
/// <summary>
///     Implements form that can host winter controls.
/// </summary>
///
class form : public services::intrusive_ptr_object {
public:
  form() : services::intrusive_ptr_object() {}

  void on_paint() {};

  ////////////////////////////////////////////////////////
  /// Methods
  ////////////////////////////////////////////////////////

  ///
  /// <summary>
  ///     Hides the form.
  /// </summary>
  ///
  void hide() const { _host.hide(); }

  ///
  /// <summary>
  ///     Shows the form as modaless.
  /// </summary>
  ///
  void show() const { _host.show(); };

  ///
  /// <summary>
  ///     Shows the form as modal.
  /// </summary>
  /// <returns>
  ///     Button id that closed the form.
  /// </returns>
  int show_modal() const { _host.show_modal(); }

  ////////////////////////////////////////////////////////
  /// Properties
  ////////////////////////////////////////////////////////

  typedef enum { TitlebarOn, TitlebarOff } TitlebarState;

  ///
  /// <summary>
  ///     Returns the titlebar on/off state.
  /// </summary>
  /// <returns>
  ///     Titlebar on/off state.
  /// </returns>
  ///
  TitlebarState get_titlebar() const {
    return _host.get_titlebar() ? TitlebarOn : TitlebarOff;
  }

  ///
  /// <summary>
  ///     Sets the titlebar on/off state.
  /// </summary>
  /// <param name="state">
  ///     Titlebar on/off state.
  /// </param>
  ///
  void set_titlebar(TitlebarState state) {
    _host.set_titlebar(state == TitlebarOn);
  }

  typedef enum { TitlebarButtonOn, TitlebarButtonOff } TitlebarButtonState;
  
  ///
  /// <summary>
  ///     Returns the system menu on/off state.
  /// </summary>
  /// <returns>
  ///     System menu on/off state.
  /// </returns>
  ///
  TitlebarButtonState get_sysmenu_button() const {
    return _host.get_sysmenu_button() ? TitlebarButtonOn : TitlebarButtonOff;
  }

  ///
  /// <summary>
  ///     Sets the system menu on/off state.
  /// </summary>
  /// <param name="state">
  ///     System menu on/off state.
  /// </param>
  ///
  void set_sysmenu_button(TitlebarButtonState state) {
    _host.set_sysmenu_button(state == TitlebarButtonOn);
  }

  ///
  /// <summary>
  ///     Returns the help button on/off state.
  /// </summary>
  /// <returns>
  ///     Help button on/off state.
  /// </returns>
  ///
  TitlebarButtonState get_help_button() const {
    return _host.get_help_button() ? TitlebarButtonOn : TitlebarButtonOff;
  }

  ///
  /// <summary>
  ///     Sets the help button on/off state.
  /// </summary>
  /// <param name="state">
  ///     Help button on/off state.
  /// </param>
  ///
  void set_help_button(TitlebarButtonState state) {
    _host.set_help_button(state == TitlebarButtonOn);
  }

  ///
  /// <summary>
  ///     Returns the minimize button on/off state.
  /// </summary>
  /// <returns>
  ///     Minimize button on/off state.
  /// </returns>
  ///
  TitlebarButtonState get_minimize_button() const {
    return _host.get_minimize_button() ? TitlebarButtonOn : TitlebarButtonOff;
  }

  ///
  /// <summary>
  ///     Sets the minimize button on/off state.
  /// </summary>
  /// <param name="state">
  ///     Minimize button on/off state.
  /// </param>
  ///
  void set_minimize_button(TitlebarButtonState state) {
    _host.set_minimize_button(state == TitlebarButtonOn);
  }

  ///
  /// <summary>
  ///     Returns the maximize button on/off state.
  /// </summary>
  /// <returns>
  ///     Maximize button on/off state.
  /// </returns>
  ///
  TitlebarButtonState get_maximize_button() const {
    return _host.get_maximize_button() ? TitlebarButtonOn : TitlebarButtonOff;
  }

  ///
  /// <summary>
  ///     Sets the maximize button on/off state.
  /// </summary>
  /// <param name="state">
  ///     Maximize button on/off state.
  /// </param>
  ///
  void set_maximize_button(TitlebarButtonState state) {
    _host.set_maximize_button(state == TitlebarButtonOn);
  }

  ////////////////////////////////////////////////////////
  /// Events
  ////////////////////////////////////////////////////////

private:
  platform::form_host<form> _host;
};

}

#endif // FORM_H
